$(function(){
    //初始化天气信息
    initTianqi();

    $('.table-sort').dataTable({
        searching:false,
        ordering:false
    });

});

function initTianqi(){
    $.ajax({
        url:'https://free-api.heweather.com/v5/weather?city=CN101200101&key=1e5624e34683417f9e4dbec1727db5dc',
        type:'get',
        dataType:'json',
        success:function(data){
            var tmpData = data.HeWeather5[0];
            if( tmpData.status == 'ok' ){
                document.getElementById('city').innerHTML = tmpData.basic.city;
                document.getElementById('date').innerHTML = tmpData.daily_forecast[0].date;
                var day = (new Date()).getDay();
                switch(day){
                    case 0:
                        day = '星期天'
                        break;
                    case 1:
                        day = '星期一'
                        break;
                    case 2:
                        day = '星期二'
                        break;
                    case 3:
                        day = '星期三'
                        break;
                    case 4:
                        day = '星期四'
                        break;
                    case 5:
                        day = '星期五'
                        break;
                    case 6:
                        day = '星期六'
                        break;
                }
                document.getElementById('day').innerHTML = day;
                document.getElementById('tianqiDetail').innerHTML = tmpData.daily_forecast[0].cond.txt_d + '转' + tmpData.daily_forecast[0].cond.txt_n;
                document.getElementById('nowTmp').innerHTML += tmpData.daily_forecast[0].tmp.min + '-' + tmpData.daily_forecast[0].tmp.max + '°C';
                document.getElementById('fengli').innerHTML += tmpData.now.wind.sc;
                document.getElementById('fengxiang').innerHTML += tmpData.now.wind.dir;
                document.getElementById('pm25').innerHTML += tmpData.aqi.city.pm25;

                document.getElementById('ziwaixian').innerHTML += tmpData.suggestion.uv.brf;
                document.getElementById('xiche').innerHTML += tmpData.suggestion.cw.brf;
                document.getElementById('gaomao').innerHTML += tmpData.suggestion.flu.brf;
                document.getElementById('chuanyi').innerHTML += tmpData.suggestion.drsg.brf;

            }else{
                layer.msg('获取天气失败，请检查网络连接情况');
            }

        }
    });
}

//数据导入按钮 点击事件
$('#dataDaoruBtn').on('click',function(){
    layer.open({
        type: 2,
        title: '数据导入',
        shadeClose: true,
        shade: 0.5,
        area: ['80%', '80%'],
        content: 'ziYuanMuLu_ShuJuDaoRu.html' //iframe的url
    });
});
